import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Question8 {
    static int ret = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        in.nextLine();
        String s = in.nextLine();

        for (int i = 1; i <= n; i++) {
            int row = i;
            int col = n / i;

            // 构不成 cow * col 的矩阵
            if (row * col != n) {
                continue ;
            }

            // 赋值矩阵
            char[][] arrs = new char[row][col];
            for (int j = 0; j < row; j++) {
                for (int k = 0; k < col; k++) {
                    arrs[j][k] = s.charAt(j * col + k);

                    // System.out.print(arrs[j][k] + " ");
                }
                // System.out.println();
            }

            // dfs 遍历
            int tol = 0;
            int[][] vis = new int[row][col];
            for (int j = 0; j < row; j++) {
                for (int k = 0; k < col; k++) {
                    if (vis[j][k] == 0) {
                        dfs(arrs, j, k, vis);
                        tol++;
                        // System.out.println(j + " " + k + " " + tol);
                    }
                }
            }


            // System.out.println(tol);

            ret = Math.min(ret, tol);
            
        }

        System.out.println(ret);
    }

    static int[][] dist = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    public static void dfs(char[][] arrs, int x, int y, int[][] vis) {
        int row = arrs.length;
        int col = arrs[0].length;

        vis[x][y] = 1;

        for (int i = 0; i < dist.length; i++) {
            int xx = x + dist[i][0];
            int yy = y + dist[i][1];

            if (xx >= 0 && xx < row && yy >= 0 && yy < col) {
                if (vis[xx][yy] == 0 && arrs[xx][yy] == arrs[x][y]) {
                    dfs(arrs, xx, yy, vis);
                }
            }
        }
    }
}